<template>
  <el-dialog title="会员红包" :visible.sync="dialogVisible">
    <p class="titl">红包余额：{{ countAmount | money }}</p>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="couponName" label="优惠名称"></el-table-column>
      <el-table-column prop="productName" label="优惠类型"></el-table-column>
      <el-table-column label="优惠券金额">
        <template slot-scope="scope">{{
          scope.row.preAmount | money
        }}</template>
      </el-table-column>
      <el-table-column label="最低消费">
        <template slot-scope="scope">{{
          scope.row.minimumAmount | money
        }}</template>
      </el-table-column>
      <el-table-column prop="minimumAmount" label="是否使用">
        <template slot-scope="scope">{{
          scope.row.used == 0 ? "未使用" : "已使用"
        }}</template>
      </el-table-column>
      <el-table-column prop="receiveTime" label="发放时间"></el-table-column>
      <el-table-column label="有效日期">
        <template slot-scope="scope">
          <span v-if="scope.row.createTime"
            >{{ scope.row.createTime | fmtdate }}至{{ scope.row.timeOut }}</span
          >
          <span v-else
            >{{ scope.row.startDate | fmtdate }}至{{
              scope.row.endDate | fmtdate
            }}</span
          >
        </template>
      </el-table-column>

      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="del(scope.row)">
            删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: right">
      <el-pagination
        @size-change="getData"
        @current-change="getData"
        :current-page.sync="queryParams.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </el-dialog>
</template>
<script>
import { delcouponMemberList } from '@/config/interface'
import { couponMemberList, getCouponValue } from '@/config/api'
export default {
  data () {
    return {
      dialogVisible: false,
      tableData: [],
      queryParams: {
        page: 1,
        pageSize: 10,
        memberId: ""
      },
      total: 0,
      countAmount: 0
    };
  },
  methods: {
    show (id) {
      console.log(id)
      this.queryParams.memberId = id
      this.getData()
      this.getCount(id)
      this.dialogVisible = true
    },
    getData () {
      couponMemberList(this.queryParams).then(res => {
        this.tableData = res.data.result.list
        this.total = res.data.result.total
      })
    },
    async getCount (id) {
      const result = await getCouponValue({ memberId: id });
      this.countAmount = result.data.result
    },
    del (row) {
      this.$confirm("删除该会员优惠券, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          delcouponMemberList({
            memberId: this.queryParams.memberId,
            memberCouponId: row.memberCouponId,
            id: row.id,
            couponName: row.couponName
          }).then(res => {
            if (res.data.status == 200) {
              this.getData();
              this.getCount(this.queryParams.memberId)

              this.$message({
                type: "success",
                message: "删除成功"
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
  }
};
</script>
<style lang="scss" scoped>
.titl {
  display: block;
  color: #f00;
  font-size: 14px;
  text-align: center;
  margin-top: 5px;
  // margin-bottom: 15px;
  position: absolute;
  left: 120px;
  top: 0;
  padding: 20px;
}
</style>